home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / DateCalc / datum.jar / InputForm.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-11-29  |  3.5 KB  |  70 lines

  1. import java.util.Calendar;
  2. import javax.microedition.lcdui.Alert;
  3. import javax.microedition.lcdui.AlertType;
  4. import javax.microedition.lcdui.Command;
  5. import javax.microedition.lcdui.CommandListener;
  6. import javax.microedition.lcdui.DateField;
  7. import javax.microedition.lcdui.Display;
  8. import javax.microedition.lcdui.Displayable;
  9. import javax.microedition.lcdui.Form;
  10. import javax.microedition.lcdui.Image;
  11. import javax.microedition.lcdui.StringItem;
  12.  
  13. class InputForm extends Form implements CommandListener {
  14.    Datum midlet;
  15.    Alert alert;
  16.    Calendar cal1 = Calendar.getInstance();
  17.    Calendar cal2 = Calendar.getInstance();
  18.    DateField datum1 = new DateField("Datum1: ", 3);
  19.    DateField datum2;
  20.    StringItem stringItem;
  21.    Command cancelCommand = new Command("Abbruch", 3, 0);
  22.    Command calcCommand = new Command("Rechne", 1, 1);
  23.    Image logo;
  24.    Image error;
  25.  
  26.    InputForm(String titel) {
  27.       super(titel);
  28.  
  29.       try {
  30.          this.logo = Image.createImage("/images/logo_max.png");
  31.          this.error = Image.createImage("/images/error.png");
  32.       } catch (Exception var3) {
  33.       }
  34.  
  35.       this.stringItem = new StringItem("Ergebnis:", "berechne alles");
  36.       this.alert = new Alert("FEHLER", "Fehler", this.error, AlertType.ERROR);
  37.       ((Form)this).append(this.logo);
  38.       ((Form)this).append(this.datum1);
  39.       ((Form)this).append(this.stringItem);
  40.       ((Displayable)this).addCommand(this.cancelCommand);
  41.       ((Displayable)this).addCommand(this.calcCommand);
  42.       ((Displayable)this).setCommandListener(this);
  43.    }
  44.  
  45.    public void commandAction(Command cmd, Displayable disp) {
  46.       if (cmd == this.calcCommand) {
  47.          String erg = null;
  48.          CalendarCalc cc = null;
  49.          this.cal1.setTime(this.datum1.getDate());
  50.  
  51.          try {
  52.             cc = new CalendarCalc(this.cal1.get(1), this.cal1.get(2) + 1, this.cal1.get(5), this.cal1.get(11), this.cal1.get(12));
  53.             erg = cc.getResultString();
  54.          } catch (Exception var6) {
  55.             this.alert.setString("Bitte nur g├╝ltige Werte eingeben!");
  56.             Display.getDisplay(this.midlet).setCurrent(this.alert);
  57.          }
  58.  
  59.          this.stringItem.setText(erg);
  60.       } else if (cmd == this.cancelCommand) {
  61.          this.midlet.viewStartForm();
  62.       }
  63.  
  64.    }
  65.  
  66.    public void setMidlet(Datum m) {
  67.       this.midlet = m;
  68.    }
  69. }
  70.